package com.hontech.bvapp2.ui.parts.drop

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.hontech.bvapp2.R
import com.hontech.bvapp2.device.cp.Drop
import com.hontech.bvapp2.ui.dialog.runProgErr
import com.hontech.bvapp2.ui.view.LabelSwitch

class DropLightLedParts (context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_drop_light_led, this)

        val led = view.findViewById<LabelSwitch>(R.id.id_drop_light_ls_led)
        val fan = view.findViewById<LabelSwitch>(R.id.id_drop_light_ls_fan)

        led.onToggleFn = { it ->
            runProgErr("照明1") {
                val ctrl = if (it) 0 else 1
                Drop.lightLed(1, ctrl)
            }
        }
        fan.onToggleFn = { it ->
            runProgErr("照明2") {
                val ctrl = if (it) 0 else 1
                Drop.lightLed(2, ctrl)
            }
        }
    }
}

